import { Request } from "express";
import { ObjectSchema } from "joi";

/**
 * @中间件校验参数
 * @param args 请求参数
 * @param schema Joi
 */
export async function validateMiddleware(args:any, schema: ObjectSchema) {
  return new Promise((resolve, reject) => {
    const { error, value } = schema.validate(args);
    if (error) {
      reject(error);
      return;
    }
    resolve(value);
  });
}
